// pages/development/development.js
let app = getApp()
let api = require("../../utils/api.js")
Page({

    /**
     * 页面的初始数据
     */
    data: {
        oType: 1,
        id: 0,
        consult: {},
        accountid: 0,
        typeid: 0,
        typearr: '',
        day: '',
        timer: '',
        startvalue: '',
        isfollow: 0,
        weekday: '',
        orderinfo: [{
            day: '',
            timer: '',
            startvalue: '',
            conslultid: '',
            typeid: 0
        }]
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        let that = this
        that.setData({
            id: options.id
        })

    },
    person: function(e) {
        var that = this;
        that.setData({
            oType: 1,
        })
    },
    consulting: function(e) {
        this.setData({
            typeid: res.currentTarget.dataset.id
        })
    },
    selecttimer: function(res) {
        this.setData({
            day: res.currentTarget.dataset.day,
            timer: res.currentTarget.dataset.value,
            startvalue: res.currentTarget.dataset.startvalue,
            weekday: res.currentTarget.dataset.weekday
        })
    },
    rorder: function(e) {
        let that = this
        if (that.data.accountid == 0) {
            api.showError("请先登录账号")
            return false
        }
        // var up = "orderinfo.day";
        // var up1 = "orderinfo.timer";
        // var up2 = "orderinfo.startvalue";
        // var up3 = "orderinfo.conslultid";
        // var up4 = "orderinfo.typeid";
        // var up5 = "orderinfo.weekday";
        // this.setData({
        //     [up]: that.data.day,
        //     [up1]: that.data.timer,
        //     [up2]: that.data.startvalue,
        //     [up3]: that.data.id,
        //     [up4]: that.data.typeid,
        //     [up5]: that.data.weekday,
        // })
        // wx.setStorage({
        //     key: 'rorderinfo',
        //     data: that.data.orderinfo,
        //     success: function() {
        //         wx.navigateTo({
        //             url: '../developorder/developorder?id=' + that.data.id
        //         })
        //     }
        // })
        if (that.data.timer == '') {
            api.showError('请选择日期')
            return false
        }
        let data = {
            uid: that.data.accountid,
            consulantid: that.data.id,
            order_date: that.data.day,
            order_between: that.data.timer,
            price: that.data.consult.basic.price,
            type: that.data.typeid
        }
        let url = app.u.HOME_URL + app.u.BOOK
        api.requestUrl(data, url).then(res => {
            if (res.code == 200) {
                api.showSuccess(res.msg)
                setTimeout(function() {
                    wx.navigateTo({
                        url: '../myorder/myorder?order_sn=' + res.order_sn
                    })
                }, 1000)
            } else {
                api.showError(res.msg)
            }

        })



    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
        let that = this

        let accountid = 0
        wx.getStorage({
            key: 'rorderinfo',
            success: function(res) {
                that.setData({
                    day: res.data.day,
                    timer: res.data.timer,
                    startvalue: res.data.startvalue,
                    typeid: res.data.typeid,
                    weekday: res.data.weekday,
                })
                that.getconsult();
            }
        })
    },
    getconsult: function() {
        let that = this
        let url = app.u.HOME_URL + app.u.CONSULT_VIEW
        wx.getStorage({
            key: 'userInfo',
            success: function(res) {
                let accountid = res.data.id
                    // success
                that.setData({
                    accountid: accountid
                })
                let data = { id: that.data.id, account_id: accountid }
                api.requestUrl(data, url).then(res => {
                    if (res.code == 200) {
                        that.setData({
                            consult: res.data,
                        })
                    } else {
                        api.showError(res.msg)
                    }
                })
            }
        })
    }
})